<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>日销售查询</title>
		<%include("/common/include.html"){}%>
		<link rel="stylesheet" href="${cxt!}/sb/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
		<style type="text/css">
			.textbox{
				padding-right:0px;
				background:url("${cxt !}/sb/themes/insdep/images/combo_arrow.png") no-repeat scroll right center transparent;
			} 
		</style>
	</head>
	<body class="easyui-layout">
			<div data-options="region:'north',split: true,title:'快速查询'" style="height:200px;padding:10px;">
				<form id="daySalesStaticFrom">
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">首次进店开始日期</label>
						<input name="startTime" value='${startTime !}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">首次进店结束日期</label>
						<input id="curDate" name="endTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">最后一次使用开始日期</label>
						<input name="lastStartTime" value='${startTime !}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">最后一次使用结束日期</label>
						<input id="curDate" name="lastEndTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">购买开始日期</label>
						<input name="buyStartTime" value='${startTime !}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">购买结束日期</label>
						<input id="curDate" name="buyEndTime" value='${date()}' class="easyui-datebox theme-textbox-radius" style="height:32px;width:212px;text-align:center" 
							data-options="editable: false,icons:[{
		                        iconCls:'icon-clear',
		                        handler: function(e){
		                            $(e.data.target).datetimespinner('clear');
		                        }
		                    }]"/>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">门店</label>
						<input id="organ" type="text" readonly style="width: 200px; height: 30px; padding-left: 10px;border-radius:3px" onclick="showMenu(); return false;" class="textbox" value="${curOrgan.name! }"/>
						<input name="organIds" id="organIds" type="hidden" value="${curOrgan.ids! }">
					</div>
					<!-- <div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">使用产品次数</label>
						<select name="use" class="easyui-combobox theme-textbox-radius"  style="width: 212px; height: 30px; padding-left: 10px;border-radius:3px" >
							<option value="0">请选择</option>
							<option value="1">0-5</option>
							<option value="2">5-10</option>
							<option value="3">10-15</option>
							<option value="4">15次以上</option>
						</select>
					</div> -->
					<!-- <div style="margin-bottom: 10px;float:left;margin-right: 10px;">
						<label class="label-top" style="width: 100%; display: block;">结余产品次数</label>
						<select name="rest" class="easyui-combobox theme-textbox-radius"  style="width: 212px; height: 30px; padding-left: 10px;border-radius:3px" >
							<option value="0">请选择</option>
							<option value="1">3次以上</option>
						</select>
					</div> -->
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='searchFrom()' class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:212px">搜索</a>
					</div>
					<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
						<a href="#" onclick='customerInfo_xls()' class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">导出</a>
					</div>
					
					</form>
	   	 	</div>
	   	 	<div data-options="region:'center',border: false" style="overflow-x:hidden;">
				<table id="daySalesTable" style="width:100%;height:100%;">
					<thead frozen="true">
						<tr>
<!-- 							<th data-options="field:'customerid',width:100,align:'center',hidden:true">customerid</th> -->
							<th data-options="field:'customername',width:100,align:'center'">顾客姓名</th>						
							<th data-options="field:'phone',width:100,align:'center'">联系方式</th>
							
						</tr>
					</thead>
					<thead>
						<tr>
							 <th data-options="field:'registtime',width:100,align:'center',rowspan:3">首次到店日期</th>
							<th data-options="field:'weight',width:100,align:'center',rowspan:3">首次体重</th>
							<th data-options="field:'std_weight',width:100,align:'center',rowspan:3">标准体重</th>
							<th data-options="field:'delweight',width:80,align:'center',rowspan:3">应减斤数</th>
							<th data-options="field:'sjjs',width:100,align:'center',rowspan:3" >实减斤数</th>
							<th data-options="field:'wjjs',width:100,align:'center',rowspan:3" formatter='format_wjjs'>未减斤数</th>
							<th data-options="field:'treatment',width:100,align:'center',rowspan:3">疗程数</th>
							<th data-options="field:'ddcs',width:100,align:'center',rowspan:3">到店次数</th>
							<th data-options="field:'zhsy',width:100,align:'center',rowspan:3">最后一次使用日期</th> 
							<th data-options="field:'date',width:100,align:'center',rowspan:3">购买日期</th> 
							<th data-options="field:'singlelc',width:100,align:'center',colspan:2" >购买产品次数</th>
							<th data-options="field:'normlc',width:100,align:'center',colspan:8" >使用产品次数</th>
							<th data-options="field:'uplc',width:100,align:'center',colspan:2" >结余产品次数</th>
							<!-- <th data-options="field:'gm_num',width:100,align:'center',colspan:${products.~size! },rowspan:2" >购买产品次数</th>
							<th data-options="field:'sy_num',width:100,align:'center',colspan:${(parts.~size + 1)*(products.~size) }" >使用产品次数</th>
							<th data-options="field:'jy_num',width:100,align:'center',colspan:${products.~size! },rowspan:2" >结余产品次数</th> -->
							<th data-options="field:'sfdb',width:100,align:'center',rowspan:3" formatter='format_sfdb'>是否达标</th> 
						</tr>
						
						 <tr>
							<th data-options="field:'_amggm',width:100,align:'center',rowspan:2" >按摩膏（25次/瓶）</th>
							<th data-options="field:'_jygm',width:100,align:'center',rowspan:2" >精油（50次/瓶）</th>
							
							<th data-options="field:'normlc_peoplenum',width:50,align:'center',colspan:4" >按摩膏（25次/瓶）</th>
							<th data-options="field:'normlc_lcnum',width:50,align:'center',colspan:4" >精油（50次/瓶）</th>
							
							<th data-options="field:'_amgsy',width:100,align:'center',rowspan:2" >按摩膏（25次/瓶）</th>
							<th data-options="field:'_jysy',width:100,align:'center',rowspan:2" >精油（50次/瓶）</th>
						
						</tr>
					
						<tr>
									<th data-options="field:'normlc_peoplenum_leg',width:25,align:'center'" >腹部</th>
									<th data-options="field:'normlc_peoplenum_1',width:25,align:'center'" >臀部</th>
									<th data-options="field:'normlc_peoplenum_leg1',width:25,align:'center'" >腿部</th>
									<th data-options="field:'normlc_peoplenum_11',width:25,align:'center'" >合计</th>
									<th data-options="field:'normlc_lcnum_leg1',width:25,align:'center'" >腹部</th>
									<th data-options="field:'normlc_lcnum_11',width:25,align:'center'" >臀部</th>
									<th data-options="field:'normlc_lcnum_leg11',width:25,align:'center'" >腿部</th>
									<th data-options="field:'normlc_lcnum_111',width:25,align:'center'" >合计</th>
						</tr> 
						<!-- <tr>
							<%if(!isEmpty(products)){
								for(product in products){%>
									<th data-options="field:'${product.ids! }',width:100,align:'center',colspan:${parts.~size + 1 }" >${product.name! }(${product.proExperience! }次/瓶)</th>
								<%}%>
							<%}%>
						</tr> -->
						<!-- <tr>
							
									<th data-options="field:'${product.ids! }0_gm',width:100,align:'center'" >Jingyou次/瓶)</th>
									<th data-options="field:'${product.ids! }1_gm',width:100,align:'center'" >按摩膏 次/瓶)</th>
								
							<%if(!isEmpty(products)){
								for(product in products){
									if(!isEmpty(parts)){
										for(part in parts){
											var field = product.bh + '_' + part.code;
											%>
											<th data-options="field:'${field! }',width:100,align:'center'" >${part.name! }使用次数</th>
										<%}%>
										<th data-options="field:'${product.ids! }_sy',width:100,align:'center'" formatter='format_sy'>使用次数合计</th>
									<%}%>
								<%}%>
							<%}%>
							<%if(!isEmpty(products)){
								for(product in products){%>
									<th data-options="field:'${product.ids! }_jy',width:100,align:'center'" >${product.name! }(${product.proExperience! }次/瓶)</th>
								<%}%>
							<%}%>
							<th data-options="field:'sum',width:50,align:'center',hidden:true" ></th>
						</tr> -->
								
							</thead>
				</table>
	    	</div>
	    	<div id="menuContent" class="menuContent" style="display: none; position: absolute;z-index: 10;">
				<ul id="organSelectTree" class="ztree" style="margin-top: 0;width: 200px;"></ul>
			</div>
		<script type="text/javascript">
			
			var $form = $('#daySalesStaticFrom');
			function searchFrom(){
				initDaySalesTable();
			}
			function customerInfo_xls(){

				var curDate = $("#curDate").val();
				var organIds = $("#organIds").val();
				var url = "${cxt!}/daySalesStatistic/excel?curDate=" + curDate + "&organIds=" + organIds;
				window.location.href = url;

			}
			$(function() {
				var $form_div = $("#daySalesStaticFrom div");
				winResize($form_div);
				$(window).resize(function(){//当调整浏览器窗口的大小时，发生 resize 事件
					winResize($form_div);
				});
			})
			function initTableTitle(){
				var name = $("#organ").val();
				return name;
			}
			function initDaySalesTable(){
				var name = initTableTitle();
				$('#daySalesTable').datagrid({
					title:name,
					cls: "theme-datagrid",
					toolbar: '#tb',
					singleSelect: true,
					rownumbers: true, //显示序号
					pagination: true,
					pageSize: 10,
					url: "customerProductPurchaseAndSaleStatisic/view",
					queryParams: sy.serializeObject($form),
				    method: 'post',
					collapsible: true,
					onLoadSuccess:function(){
						var rows = $('#daySalesTable').datagrid('getRows');
						

							$('#daySalesTable').datagrid('mergeCells',{
								index: rows.length - 1,
								field: 'date',
								colspan: 4
							});
					},
					onClickRow:function(rowIndex,rowData){
					}
				});
			}
			function format_sy(value,row){
				if(typeof(value) == 'number'){
					return value.toFixed(1);
           	 	}else{
           	 		return value;
           	 	}
			}
			function format_wjjs(value,row){
				var wjjs = 0;
				if(typeof(row.delweight) != 'undefined' && typeof(row.sjjs) != 'undefined'){
					wjjs = parseFloat(row.delweight)-parseFloat(row.sjjs);
           	 	}
				
				
	            	return wjjs;
	           
			}
			function format_sfdb(value,row){
				var sfdb = "否";
				if(typeof(row.delweight) != 'undefined' && typeof(row.sjjs) != 'undefined'){
					if((parseFloat(row.delweight))<=(parseFloat(row.sjjs))){
						sfdb = "是";
					}
           	 	}
				
				
	            	return sfdb;
	           
			}
			
			
		</script>
		<script type="text/javascript">
			var setting = {
				async : {
					enable : true,
					url : '${cxt!}/common/getOrgenTree',
					autoParam : [ "id=ids" ],//, "name=n", "level=lv"
					type : "post"
				},
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClick,
					onAsyncSuccess : organTreeOnAsyncSuccess
				}
			};
			var flag=0;//只初始化一次标识
			function organTreeOnAsyncSuccess(event, treeId, msg) {
				if(flag == 0){
					flag = 1;
					initDaySalesTable();
					
				}
			}
			function onClick(e, treeId, treeNode) {
				var zTree = $.fn.zTree.getZTreeObj("organSelectTree");
				var path = "";
				var sNodes = zTree.getSelectedNodes();
				if (sNodes.length > 0) {
					var node = sNodes[0].getPath();
					for(var i =0;i<node.length;i++){
						if(i == (node.length-1)){
							path += node[i].name;
						}else{
							path += node[i].name + "/";
						}
						
					}
				}
				var cityObj = $("#organ");
				cityObj.attr("value", path);
				$("#organIds").attr("value", treeNode.id);
				hideMenu();
			}
			function showMenu() {
				var cityObj = $("#organ");
				var cityOffset = $("#organ").offset();
				$("#menuContent").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
		
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#menuContent").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "menuBtn"
						|| event.target.id == "menuContent" || $(event.target)
						.parents("#menuContent").length > 0)) {
					hideMenu();
				}
			}
			$.fn.zTree.init($("#organSelectTree"), setting);
		</script>
	</body>
</html>
